import 'package:dailoz/generated/l10n.dart';
import 'package:dailoz/main.dart';
import 'package:dailoz/utils/reg_exps.dart';
import 'package:dailoz/utils/toast.dart';
import 'package:flutter/material.dart';

class Validate {
  static bool validatePhoneNumber(String phoneNum) {
    BuildContext? context = navigatorKey.currentState?.overlay?.context;
    if (phoneNum.isEmpty) {
      showToast(S.of(context!).phoneNotNull);
      return false;
    } else {
      if (RegExps.phoneExp.hasMatch(phoneNum)) {
        return true;
      }
      return false;
    }
  }

  static bool validatePassword(String password) {
    BuildContext? context = navigatorKey.currentState?.overlay?.context;
    if (password.isEmpty) {
      showToast(S.of(context!).passwordNotNull);
      return false;
    } else {
      if (RegExps.passwordExp.firstMatch(password) != null) {
        return true;
      }
      showToast(S.of(context!).passwordConfirm);
      return false;
    }
  }

  static bool validateCode(String num) {
    BuildContext? context = navigatorKey.currentState?.overlay?.context;
    if (num.isEmpty) {
      showToast(S.of(context!).codeNotNull);
      return false;
    } else {
      if (RegExps.numberExp.hasMatch(num)) {
        return true;
      }
      showToast(S.of(context!).validateCodeError);
      return false;
    }
  }

  static bool validateUserName(String userName) {
    BuildContext? context = navigatorKey.currentState?.overlay?.context;
    if (userName.isEmpty) {
      showToast(S.of(context!).usernameNotNull);
      return false;
    } else {
      if (RegExps.userNameExp.hasMatch(userName)) {
        return true;
      }
      showToast(S.of(context!).userNameError);
      return false;
    }
  }
}
